package com.rentcars.utils;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 类描述：Md5加密工具类，不可逆
 *
 * @author 张吉哲
 * @date 2020/12/17 10:49
 */
public class Md5Util {

    public static String md5(String text) {
        StringBuilder sb = new StringBuilder();
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] digest = md.digest(text.getBytes(StandardCharsets.UTF_8));
            //将字节转化为16进制字符串
            for (byte b : digest) {
                sb.append(Integer.toHexString(b & 0xff));
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println(md5("www123456"));
    }
}
